package com.gimi.test_jpa.com.gimi.controller.customer;


import com.gimi.test_jpa.com.gimi.dto.customer.CustomerAttachmentDto;
import com.gimi.test_jpa.com.gimi.dto.customer.CustomerDto;
import com.gimi.test_jpa.com.gimi.service.customer.CustomerAttachmentService;
import com.gimi.test_jpa.com.gimi.service.customer.CustomerContactInfoService;
import com.gimi.test_jpa.com.gimi.service.customer.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/cus")
@RestController
//@ResultInterceptor
@Api(description = "客户管理")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @Autowired
    private CustomerAttachmentService customerAttachmentService;
    @Autowired
    private CustomerContactInfoService customerContactInfoService;

    /**
     * 创建修改客户
     * @param dto
     * @return
     */
    @ApiOperation("创建修改客户")
    @PostMapping("/createAndUpdateCus")
    public Boolean createCus(@RequestBody CustomerDto dto){
        //校验参数

        return customerService.createAndUpdateCus(dto);
    }


    /**
     * 根据客户Id 删除客户
     * @param cusId
     * @return
     */
    @ApiOperation("根据客户Id 删除客户")
    @PostMapping("/deleteCus")
    public Boolean deletaCus(@RequestParam("cusId") String cusId){
        if (cusId==null){
            throw new RuntimeException("客户ID不能为空");
        }
        return customerService.deleteCus(cusId);
    }

    /**
     * 根据客户Id查询客户信息
     * @param cusId
     * @return
     */
    @ApiOperation("根据客户Id查询客户信息")
    @PostMapping("/findByCusId")
    public CustomerDto findByCusId(@RequestParam("cusId") String cusId){
        if (cusId==null){
            throw new RuntimeException("客户ID不能为空");
        }
        return customerService.findByCusId(cusId);
    }

    /**
     * 创建客户附件信息
     * @param dto
     * @return
     */
    @ApiOperation("创建客户附件信息")
    @PostMapping("/createCusAtt")
    public Boolean createCus(@RequestBody CustomerAttachmentDto dto){
        //校验参数
        if (dto.getCusId()==null){
            throw new RuntimeException("客户附件信息Id不能为空");
        }
        return customerAttachmentService.createCusAtt(dto);
    }

    /**
     * 根据附件信息Id删除客户附件信息
     * @param attId
     * @return
     */
    @ApiOperation("根据附件信息Id删除客户附件信息")
    @PostMapping("/deleteCusAtt")
    public Boolean deletaCusAtt(@RequestParam("attId") String attId){
        if (attId==null){
            throw new RuntimeException("附件信息ID不能为空");
        }
        return customerAttachmentService.deleteCusAtt(attId);
    }

    /**
     * 修改客户附件信息
     * @param dto
     * @return
     */
    @ApiOperation("修改客户附件信息")
    @PostMapping("/updateCusAtt")
    public Boolean updateCus(@RequestBody CustomerAttachmentDto dto){
        //校验参数
        if (dto.getAttId()==null){
            throw new RuntimeException("客户附件信息ID不能为空");
        }
        return customerAttachmentService.updateCusAtt(dto);
    }

    /**
     * 根据客户附件信息Id查询客户附件信息
     * @param attId
     * @return
     */
    @ApiOperation("根据客户附件信息Id查询客户附件信息")
    @GetMapping("/findAttByAttId")
    public CustomerAttachmentDto findAttByAttId(@RequestParam("attId") String attId){
        if (attId==null){
            throw new RuntimeException("客户附件信息ID不能为空");
        }
        return customerAttachmentService.findByAttId(attId);
    }

    /**
     * 根据客户Id查询客户附件信息
     * @param cusId
     * @return
     */
    @ApiOperation("根据客户Id查询客户附件信息")
    @GetMapping("/findAttByCusId")
    public CustomerAttachmentDto findAttByCusId(@RequestParam("cusId") String cusId){
        if (cusId==null){
            throw new RuntimeException("客户ID不能为空");
        }
        return customerAttachmentService.findByCusId(cusId);
    }
}
